<template>
  <div>
    <div>
      医院提交修改（未审核）
    </div>
    <el-table :data="tableData"
              :header-cell-style="{background:'#f2f5fc',color:'#555'}"
              border>
      <el-table-column prop="userId" label="ID" width="60">
      </el-table-column>
      <el-table-column prop="name" label="院名" width="120">
      </el-table-column>
      <el-table-column prop="phone" label="联系方式" width="100">
      </el-table-column>
      <el-table-column prop="dailyclinic" label="日诊人数" width="80">
      </el-table-column>
      <el-table-column prop="bed" label="床位数" width="80">
      </el-table-column>
      <el-table-column prop="email" label="邮箱" width="120">
      </el-table-column>
      <el-table-column prop="address" label="地址" width="140">
      </el-table-column>
      <el-table-column prop="membership" label="隶属性质" width="80">
      </el-table-column>
      <el-table-column prop="type" label="医院类别" width="80">
      </el-table-column>
      <el-table-column prop="total" label="总人数" width="80">
      </el-table-column>
      <el-table-column prop="operate" label="操作">
        <template slot-scope="scope">
          <el-popconfirm title="确定通过吗？" @confirm="mod(scope.row)" style="margin-left: 5px">
            <el-button slot="reference" size="small" type="success">通过</el-button>
          </el-popconfirm>
          <el-popconfirm title="确定不通过吗？" @confirm="del(scope.row.userId)" style="margin-left: 5px">
            <el-button slot="reference" size="small" type="danger">不通过</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        :current-page="pageNum"
        :page-sizes="[5, 10, 20,30]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
    >
      <!--        @size-change="handleSizeChange"-->
      <!--        @current-change="handleCurrentChange"-->
    </el-pagination>
  </div>
</template>

<script>
import {deleHosS, selectAllS, updateById} from "@/api/hospital";

export default {
  name: "Check",
  data() {
    return {
      flag: 0,
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      name: '',
      centerDialogVisible: false,
      form: {
        userId: "",
        name: "",
        phone: "",
        dailyclinic: "", //日均出诊人数
        bed: "",  //床位
        email: "",
        address: "",
        membership: "",
        type: "",
        total: ""
      }
    }
  },
  methods: {
    loadPost() {
      selectAllS({}).then((res) => {
        if (res.flag == true) {
          this.tableData = res.data
          this.total = res.data.length
        } else {
          alert("获取数据失败")
        }
      })
    },
    mod(row) {
      console.log(row)
      updateById({
        userId: row.userId,
        name: row.name,
        phone: row.phone,
        dailyclinic: row.dailyclinic, //日均出诊人数
        bed: row.bed,  //床位
        email: row.email,
        address: row.address,
        membership: row.membership,
        type: row.type,
        total: row.total,
      }).then((res) => {
        if (res.flag == true) {
          deleHosS({
            id: row.userId
          }).then((res) => {
            if (res.flag == true) {
              this.$message.success("审核通过");
              this.loadPost()
            } else {
              this.$message.error(res.data);
            }
          })
              .catch((err) => {
                console.log("删除失败");
              });
          this.loadPost()
        } else {
          this.$message.error(res.data);
        }
      }).catch((err) => {
        console.log("修改失败");
      });
    },
    del(id) {
      deleHosS({
        id: id
      }).then((res) => {
        if (res.flag == true) {
          this.$message.success("审核未通过");
          this.loadPost()
        } else {
          this.$message.error(res.data);
        }
      }).catch((err) => {
        console.log("删除失败");
      });
    }
  },
  created() {
    this.loadPost()
  }
}
</script>

<style scoped>

</style>